# working directory ---------------------------
setwd("~/Library/CloudStorage/OneDrive-UniversitédeGenève/oecd-dac-project-unige/paper-gender-targeting/2025-ddfi-isq-replication")

# packages ---------------------------
library(tidyverse)
library(lfe) # for felm()

# data ---------------------------
ry <- read_csv("2025-ddfi-isq-data-ry.csv") # recipient-year level, built including eu lines 
dry <- read_csv("2025-ddfi-isq-data-dry.csv") # donor-recipient-year level

# t1 replication with recipient FEs ---------------------------
m_a1 <- felm(commit_gender_1_pct ~ vdem_row_id_ry + quota_adpt_ry 
           + log(gdppc_ry) + dependence_ry 
           | r + y | 0 | r, 
           data = ry)

m_a2 <- felm(commit_gender_1_pct ~ vdem_row_id_ry + wbl_ry 
           + log(gdppc_ry) + dependence_ry 
           | r + y | 0 | r, 
           data = ry)

m_a3 <- felm(commit_gender_1_pct ~ vdem_row_id_ry * quota_adpt_ry 
           + log(gdppc_ry) + dependence_ry 
           | r + y | 0 | r, 
           data = ry)

m_a4 <- felm(commit_gender_1_pct ~ vdem_row_id_ry * wbl_ry 
           + log(gdppc_ry) + dependence_ry 
           | r + y | 0 | r, 
           data = ry)

m_a5 <- felm(commit_gender_1_pct ~ vdem_row_id_ry * quota_adpt_ry 
           + log(gdppc_ry) + dependence_ry + importance_rtod_dry + seats_dy 
           | d + r + y | 0 | r, 
           data = dry)

m_a6 <- felm(commit_gender_1_pct ~ vdem_row_id_ry * wbl_ry 
           + log(gdppc_ry) + dependence_ry + importance_rtod_dry + seats_dy 
           | d + r + y | 0 | r, 
           data = dry)

# t1 replication with other measures of regime type ---------------------------
# RoW ambiguous coding ---------------------------
# democracy = vdem_row_id_amb_ry
m_a7 <- felm(commit_gender_1_pct ~ vdem_row_id_amb_ry + quota_adpt_ry 
           + log(gdppc_ry) + dependence_ry 
           | y | 0 | r, 
           data = ry)

m_a8 <- felm(commit_gender_1_pct ~ vdem_row_id_amb_ry + wbl_ry 
           + log(gdppc_ry) + dependence_ry 
           | y | 0 | r, 
           data = ry)

m_a9 <- felm(commit_gender_1_pct ~ vdem_row_id_amb_ry * quota_adpt_ry 
           + log(gdppc_ry) + dependence_ry 
           | y | 0 | r, 
           data = ry)

m_a10 <- felm(commit_gender_1_pct ~ vdem_row_id_amb_ry * wbl_ry 
           + log(gdppc_ry) + dependence_ry 
           | y | 0 | r, 
           data = ry)

m_a11 <- felm(commit_gender_1_pct ~ vdem_row_id_amb_ry * quota_adpt_ry 
           + log(gdppc_ry) + dependence_ry + importance_rtod_dry + seats_dy 
           | d + y | 0 | r, 
           data = dry)

m_a12 <- felm(commit_gender_1_pct ~ vdem_row_id_amb_ry * wbl_ry 
           + log(gdppc_ry) + dependence_ry + importance_rtod_dry + seats_dy 
           | d + y | 0 | r, 
           data = dry)

# RoW four levels ---------------------------
# democracy = vdem_row_ry
m_a13 <- felm(commit_gender_1_pct ~ vdem_row_ry + quota_adpt_ry 
           + log(gdppc_ry) + dependence_ry 
           | y | 0 | r, 
           data = ry)

m_a14 <- felm(commit_gender_1_pct ~ vdem_row_ry + wbl_ry 
           + log(gdppc_ry) + dependence_ry 
           | y | 0 | r, 
           data = ry)

m_a15 <- felm(commit_gender_1_pct ~ vdem_row_ry * quota_adpt_ry 
           + log(gdppc_ry) + dependence_ry 
           | y | 0 | r, 
           data = ry)

m_a16 <- felm(commit_gender_1_pct ~ vdem_row_ry * wbl_ry 
           + log(gdppc_ry) + dependence_ry 
           | y | 0 | r, 
           data = ry)

m_a17 <- felm(commit_gender_1_pct ~ vdem_row_ry * quota_adpt_ry 
           + log(gdppc_ry) + dependence_ry + importance_rtod_dry + seats_dy 
           | d + y | 0 | r, 
           data = dry)

m_a18 <- felm(commit_gender_1_pct ~ vdem_row_ry * wbl_ry 
           + log(gdppc_ry) + dependence_ry + importance_rtod_dry + seats_dy 
           | d + y | 0 | r, 
           data = dry)

# EDI continous democracy ---------------------------
# democracy = vdem_edi_ry
m_a19 <- felm(commit_gender_1_pct ~ vdem_edi_ry + quota_adpt_ry 
           + log(gdppc_ry) + dependence_ry 
           | y | 0 | r, 
           data = ry)

m_a20 <- felm(commit_gender_1_pct ~ vdem_edi_ry + wbl_ry 
           + log(gdppc_ry) + dependence_ry 
           | y | 0 | r, 
           data = ry)

m_a21 <- felm(commit_gender_1_pct ~ vdem_edi_ry * quota_adpt_ry 
           + log(gdppc_ry) + dependence_ry 
           | y | 0 | r, 
           data = ry)

m_a22 <- felm(commit_gender_1_pct ~ vdem_edi_ry * wbl_ry 
           + log(gdppc_ry) + dependence_ry 
           | y | 0 | r, 
           data = ry)

m_a23 <- felm(commit_gender_1_pct ~ vdem_edi_ry * quota_adpt_ry 
           + log(gdppc_ry) + dependence_ry + importance_rtod_dry + seats_dy 
           | d + y | 0 | r, 
           data = dry)

m_a24 <- felm(commit_gender_1_pct ~ vdem_edi_ry * wbl_ry 
           + log(gdppc_ry) + dependence_ry + importance_rtod_dry + seats_dy 
           | d + y | 0 | r, 
           data = dry)

# BMR dichotomous ---------------------------
# democracy = bmr_ry
m_a25 <- felm(commit_gender_1_pct ~ bmr_ry + quota_adpt_ry 
           + log(gdppc_ry) + dependence_ry 
           | y | 0 | r, 
           data = ry)

m_a26 <- felm(commit_gender_1_pct ~ bmr_ry + wbl_ry 
           + log(gdppc_ry) + dependence_ry 
           | y | 0 | r, 
           data = ry)

m_a27 <- felm(commit_gender_1_pct ~ bmr_ry * quota_adpt_ry 
           + log(gdppc_ry) + dependence_ry 
           | y | 0 | r, 
           data = ry)

m_a28 <- felm(commit_gender_1_pct ~ bmr_ry * wbl_ry 
           + log(gdppc_ry) + dependence_ry 
           | y | 0 | r, 
           data = ry)

m_a29 <- felm(commit_gender_1_pct ~ bmr_ry * quota_adpt_ry 
           + log(gdppc_ry) + dependence_ry + importance_rtod_dry + seats_dy 
           | d + y | 0 | r, 
           data = dry)

m_a30 <- felm(commit_gender_1_pct ~ bmr_ry * wbl_ry 
           + log(gdppc_ry) + dependence_ry + importance_rtod_dry + seats_dy 
           | d + y | 0 | r, 
           data = dry)

# m5 and m6 with other donor-level controls ---------------------------
m_a31 <- felm(commit_gender_1_pct ~ vdem_row_id_ry * quota_adpt_ry 
             + log(gdppc_ry) + dependence_ry + importance_rtod_dry + wngos_dy 
             | d + y | 0 | r, 
             data = dry)

m_a32 <- felm(commit_gender_1_pct ~ vdem_row_id_ry * quota_adpt_ry 
             + log(gdppc_ry) + dependence_ry + importance_rtod_dry + fem_minist_dy
             | d + y | 0 | r, 
             data = dry)

m_a33 <- felm(commit_gender_1_pct ~ vdem_row_id_ry * quota_adpt_ry 
             + log(gdppc_ry) + dependence_ry + importance_rtod_dry + seats_dy + wngos_dy + fem_minist_dy
             | d + y | 0 | r, 
             data = dry)

m_a34 <- felm(commit_gender_1_pct ~ vdem_row_id_ry * wbl_ry 
             + log(gdppc_ry) + dependence_ry + importance_rtod_dry + wngos_dy 
             | d + y | 0 | r, 
             data = dry)

m_a35 <- felm(commit_gender_1_pct ~ vdem_row_id_ry * wbl_ry 
             + log(gdppc_ry) + dependence_ry + importance_rtod_dry + fem_minist_dy 
             | d + y | 0 | r, 
             data = dry)

m_a36 <- felm(commit_gender_1_pct ~ vdem_row_id_ry * wbl_ry 
             + log(gdppc_ry) + dependence_ry + importance_rtod_dry + seats_dy + wngos_dy + fem_minist_dy
             | d + y | 0 | r, 
             data = dry)

# t1 replication with other outcomes ---------------------------
# gepm primary targeting ---------------------------
# outcome = commit_gender_2_pct
m_a37 <- felm(commit_gender_2_pct ~ vdem_row_id_ry + quota_adpt_ry 
           + log(gdppc_ry) + dependence_ry 
           | y | 0 | r, 
           data = ry)

m_a38 <- felm(commit_gender_2_pct ~ vdem_row_id_ry + wbl_ry 
           + log(gdppc_ry) + dependence_ry 
           | y | 0 | r, 
           data = ry)

m_a39 <- felm(commit_gender_2_pct ~ vdem_row_id_ry * quota_adpt_ry 
           + log(gdppc_ry) + dependence_ry 
           | y | 0 | r, 
           data = ry)

m_a40 <- felm(commit_gender_2_pct ~ vdem_row_id_ry * wbl_ry 
           + log(gdppc_ry) + dependence_ry 
           | y | 0 | r, 
           data = ry)

m_a41 <- felm(commit_gender_2_pct ~ vdem_row_id_ry * quota_adpt_ry 
           + log(gdppc_ry) + dependence_ry + importance_rtod_dry + seats_dy 
           | d + y | 0 | r, 
           data = dry)

m_a42 <- felm(commit_gender_2_pct ~ vdem_row_id_ry * wbl_ry 
           + log(gdppc_ry) + dependence_ry + importance_rtod_dry + seats_dy 
           | d + y | 0 | r, 
           data = dry)

# two gender purpose codes ---------------------------
# outcome = commit_purpose_both_pct
m_a43 <- felm(commit_purpose_both_pct ~ vdem_row_id_ry + quota_adpt_ry 
           + log(gdppc_ry) + dependence_ry 
           | y | 0 | r, 
           data = ry)

m_a44 <- felm(commit_purpose_both_pct ~ vdem_row_id_ry + wbl_ry 
           + log(gdppc_ry) + dependence_ry 
           | y | 0 | r, 
           data = ry)

m_a45 <- felm(commit_purpose_both_pct ~ vdem_row_id_ry * quota_adpt_ry 
           + log(gdppc_ry) + dependence_ry 
           | y | 0 | r, 
           data = ry)

m_a46 <- felm(commit_purpose_both_pct ~ vdem_row_id_ry * wbl_ry 
           + log(gdppc_ry) + dependence_ry 
           | y | 0 | r, 
           data = ry)

m_a47 <- felm(commit_purpose_both_pct ~ vdem_row_id_ry * quota_adpt_ry 
           + log(gdppc_ry) + dependence_ry + importance_rtod_dry + seats_dy 
           | d + y | 0 | r, 
           data = dry)

m_a48 <- felm(commit_purpose_both_pct ~ vdem_row_id_ry * wbl_ry 
           + log(gdppc_ry) + dependence_ry + importance_rtod_dry + seats_dy 
           | d + y | 0 | r, 
           data = dry)